<template>
	<view class="main">
		<u-navbar :is-back="true" title=" " :background="background" :border-bottom="false" itle-color="#fff"
			back-icon-color="#fff">
			<view class="slot-wrap">

			</view>
		</u-navbar>
		<view class="all">
			<view class="background">
				<image src="../../../static/images/shareback.png" mode=""></image>
			</view>
			<view class="tips">
				<text>{{tips}}</text>
			</view>
			<view class="top">
				<view class="first">
					<view>
						{{nowMoney}}
					</view>
					<text>{{i18n.commission_details.total}}</text>
				</view>
			</view>
			<view class="second">
				<view class="sec_l">
					<view>
						{{beenMoney}}
					</view>
					<text>{{i18n.commission_details.settled}}</text>
				</view>
				<view class="sec_l">
					<view>
						{{sureMoney}}
					</view>
					<text>{{i18n.commission_details.billable}}</text>
				</view>
			</view>
			<view class="button" @click="router">
				{{i18n.commission_details.settlement_apply}}
			</view>
			<view class="usernum">
				<view class="num_tit">
					{{i18n.commission_details.Number_of}}
				</view>
				<view class="peoplenum">
					<u-button class="btn" :class="{'on':level == 0}" :ripple="true"  @click="btnLeveClick(0)" ripple-bg-color="#909399">
						<view class="people_t">
							<view class="people_num">
								<text>{{levelUserNum}}</text> {{i18n.commission_details.person}}
							</view>
							<view class="grade">
								{{i18n.commission_details.all}}
							</view>
						</view>
					</u-button>
					<u-button class="btn btn-left" :class="{'on':level == 1}" :ripple="true"  @click="btnLeveClick(1)" ripple-bg-color="#909399">
						<view class="people_t">
							<view class="people_num">
								<text>{{level1UserNum}}</text> {{i18n.commission_details.person}}
							</view>
							<view class="grade">
								{{i18n.commission_details.grade}}
							</view>
						</view>
					</u-button>
					<u-button class="btn btn-left" :class="{'on':level == 2}" :ripple="true"  @click="btnLeveClick(2)" ripple-bg-color="#909399">
						<view class="people_t">
							<view class="people_num">
								<text>{{level2UserNum}}</text> {{i18n.commission_details.person}}
							</view>
							<view class="grade">
								{{i18n.commission_details.grade2}}
							</view>
						</view>
					</u-button>
					<u-button class="btn btn-left" :class="{'on':level == 3}" :ripple="true"  @click="btnLeveClick(3)" ripple-bg-color="#909399">
						<view class="people_t">
							<view class="people_num">
								<text>{{level3UserNum}}</text> {{i18n.commission_details.person}}
							</view>
							<view class="grade">
								{{i18n.commission_details.grade3}}
							</view>
						</view>
					</u-button>
				</view>
			</view>
			<view class="details_tit">
				{{i18n.commission_details.detailed_list}}
			</view>
			
			
 
			<scroll-view scroll-y :style="{'height':vHeight + 'px'}" @scrolltolower="reachBottom">	
				<view class="details" v-for="(item, index) in inviteList" :key="index">
					<view class="details_l">
						<image :src="item.avatar ? item.avatar : '../../../static/images/simple.webp'"  :onerror="defaultAvatar" mode=""></image>
					</view>
					<view class="details_r">
						<view class="userinfo">
							<text>{{item.name}}</text>
							<text class="grade" v-if="item.level==1">{{i18n.commission_details.grade}}</text>
							<text class="grade" v-if="item.level==2">{{i18n.commission_details.grade2}}</text>
							<text class="grade" v-if="item.level==3">{{i18n.commission_details.grade3}}</text>
						</view>
						<view class="volume">
							<view class="one_of">
								<text>{{item.onSaleNum}}</text>
								<text class="tit_of">{{i18n.commission_details.resale_quantity}}</text>
							</view>
							<view class="one_of">
								<text>{{item.soldNum}}</text>
								<text class="tit_of">{{i18n.commission_details.quantity_sold}}</text>
							</view>
							<view class="one_of">
								<text>{{item.childNum}}</text>
								<text class="tit_of">{{i18n.commission_details.child_num}}</text>
							</view>
						</view>
						<view class="money">
							<view class="money_l">
								<text class="tit">{{i18n.commission_details.commission_amount}}：</text>
								<text class="money">{{item.comMoney}}</text>
							</view>
							<view class="money_l">
								<text class="tit">{{i18n.commission_details.create_time}}：</text>
								<text class="date">{{item.createTime}}</text>
							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" :load-text="i18n.commission_details.loadText"/>
			</scroll-view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#304156',
				},
				beenMoney: "0.00",
				levelUserNum: 0,
				level1UserNum: 0,
				level2UserNum: 0,
				level3UserNum: 0,
				nowMoney: "0.00",
				sureMoney: "0.00",
				tips: "",
				level: 0,
				status: 'loadmore',
				inviteList: [],
				currentPage: 0,
				totalPage: 0,
				vHeight: 450
			}
		},
		computed: {
			i18n() {
				return this.$t('message')
			},
			defaultAvatar() {
			  return 'this.src="'+ require('../../../static/images/simple.webp') +'"'
			}
		},
		onLoad() {
			this.getCommissionData();
			this.getInviteListData();
		},
		onShow() {
			this.lang();
			uni.getSystemInfo({ 
				success: (res) => {
					this.vHeight = res.windowHeight - 363;
				}
			});
		},
		methods: {
			lang() {
				this._i18n.locale = uni.getStorageSync('select')
			},
			reachBottom() {
				this.getInviteListData();
			},
			btnLeveClick(lv) {
				this.level = lv;
				//this.$u.toast(this.i18n.commission_details.loading);
				this.inviteList = [];
				this.currentPage = 0;
				this.totalPage = 0;
				this.getInviteListData();
			},
			getCommissionData() {
				global.$http.request({
					url: '/api/admin/merchant/commission',
					header: {
							'Authori-zation':  uni.getStorageSync('token') //自定义请求头信息
						},
					method: 'GET',
				}).then(res => {
					if (res.data.code == 200) {
						this.beenMoney = res.data.data.beenMoney;
						this.level1UserNum = res.data.data.level1UserNum;
						this.level2UserNum = res.data.data.level2UserNum;
						this.level3UserNum = res.data.data.level3UserNum;
						this.levelUserNum = this.level1UserNum + this.level2UserNum +this.level3UserNum ;
						this.nowMoney = res.data.data.nowMoney;
						this.sureMoney = res.data.data.sureMoney;
						this.tips = res.data.data.tips; 
					}
				})
			},
			getInviteListData() {
				this.status = 'loading';
				if(this.currentPage>0 && this.totalPage>0 && this.currentPage>=this.totalPage){
					this.status = 'nomore';
					return
				}
				global.$http.request({
					url: '/api/admin/merchant/inviteLsit/' + this.level,
					header: {
							'Authori-zation':  uni.getStorageSync('token') //自定义请求头信息
						},
					method: 'GET',
					data:{
					  page: this.currentPage+1
					}
				}).then(res => {
					if (res.data.code == 200) {
						this.inviteList = this.inviteList.concat(res.data.data.list);
						this.currentPage = res.data.data.page;
						this.totalPage = res.data.data.totalPage;
						if(this.currentPage>=this.totalPage){
							this.status = 'nomore';
						}else{
							this.status = 'loadmore';
						}
					}
				})
			},
			router(){
				uni.navigateTo({
					url:'../settlement_apply/settlement_apply'
				})
			}
		},
		
	}
</script>

<style lang="scss">
	page {
		font-family: PingFang SC;
		background-color: #f7f7f7;

		.main {
			overflow: hidden;
			.slot-wrap {
				width: 590rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
			}

			.all {
				.background {
					image {
						position: absolute;
						top: 0rpx;
						z-index: 0;
						width: 750rpx;
						height: 456rpx;
					}
				}
				.tips{
					position: relative;
					padding-left: 1rem;
					padding-bottom: 0.8rem;
					text {
						font-size: 22rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						z-index: 0;
					}
				}
				.top {
					.first {
						display: flex;
						flex-direction: column;
						align-items: center;
						z-index: 0;
						view {
							font-size: 30rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
							z-index: 0;
						}

						text {
							font-size: 22rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
							z-index: 0;
						}
					}
				}

				.second {
					padding: 29rpx 72rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.sec_l {
						display: flex;
						flex-direction: column;
						align-items: center;

						view {
							font-size: 30rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
							z-index: 0;
						}

						text {
							font-size: 22rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
							z-index: 0;
						}
					}
				}

				.button {
					width: 180rpx;
					text-align: center;
					line-height: 54rpx;
					margin: 0 auto 20rpx auto;
					height: 54rpx;
					background: #FFFFFF;
					border-radius: 27px;
					
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #304156;
					z-index: 0;
					position: relative;
				}

				.usernum {
					padding: 25rpx 32rpx;
					width: 696rpx;
					margin: 0 auto;
					background: #FFFFFF;
					border-radius: 20rpx;
					position: relative;
					
					.num_tit {
						font-size: 22rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #999999;
						padding-bottom: 28rpx;
					}

					.peoplenum {
						display: flex;
						justify-content: space-around;
						align-items: center;
						.btn-left{
						    margin-left: 10px;
						}
						.btn{
							height: 50px;
							padding: 0 10px;
							width: 100%;
							.people_t {
								display: flex;
								flex-direction: column;
								align-items: center;
								height: 55px;
								.people_num {
								    height: 20px;
								}
								text {
									font-size: 30rpx;
									font-family: PingFang SC;
									font-weight: 400;
									color: #000000;
									padding-right: 4px;
									color: #FE2C58;
								}

								font-size: 18rpx;
								font-family: PingFang SC;
								font-weight: 400;
								color: #FE2C58;
							}

							.grade {
								font-size: 22rpx;
								font-family: PingFang SC;
								font-weight: 400;
								color: #000000;
							}
						}
						.on {
						    background-color: #e5e5e5;
						}
					}
				}

				.details_tit {
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #000000;
					padding: 35rpx 33rpx;
				}

				.details {
					margin-bottom: 10rpx;
					width: 750rpx;
					display: flex;
					// align-items: center;
					padding: 12rpx 35rpx 28rpx 35rpx;
					background-color: #fff;

					.details_l {
						padding-top: 20rpx;
						image {
							width: 76rpx;
							height: 76rpx;
							border-radius: 100%;
						}
					}

					.details_r {
						width: 89%;
						.userinfo{
							padding: 36rpx 19rpx;
							display: flex;
							justify-content: space-between;
							align-items: center;
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: 400;
							border-bottom: 2rpx solid #C5C5C5;
							text{
								display: block;
								color: #141414;
							}
							.grade{
							color: #0E90FF;
							}
						}
							
						.volume{
							display: flex;
							justify-content: space-between;
							align-items: center;
							padding: 22rpx 17rpx 30rpx 17rpx;
							text-align: center;
							.one_of{
								display: flex;
								flex-direction: column;
								align-items: center;
								font-size: 26rpx;
								font-family: PingFang SC;
								font-weight: 400;
								color: #000000;
								.tit_of{
									font-size: 20rpx;
									font-family: PingFang SC;
									font-weight: 400;
									color: #999999;
									padding: 0 6px 0 6px;
								}
							}
							
						}
						.money{
							display: flex;
							justify-content: space-between;
							align-items: center;
							.money_l{
								display: flex;
								align-items: center;
								.tit{
									font-size: 24rpx;
									font-family: PingFang SC;
									font-weight: 400;
									color: #999999;
								}
								.date{
									font-size: 24rpx;
									font-family: PingFang SC;
									font-weight: 400;
									color: #141414;
								}
								.money{
									font-size: 24rpx;
									font-family: PingFang SC;
									font-weight: 400;
									color: #FF0000;
								}
							}
							
						}
					}
				}
			}
		}
	}
</style>
